{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1d0426df",
   "metadata": {},
   "source": [
    "### 暂停一秒输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ca8f1f17",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-31T13:32:30.666548Z",
     "start_time": "2021-10-31T13:32:27.634952Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3]\n",
      "[1, 2, 3]\n",
      "[1, 2, 3]\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "a = [1,2,3]\n",
    "for i in range(len(a)):\n",
    "    print (a)\n",
    "    time.sleep(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4443128",
   "metadata": {},
   "source": [
    "### 暂停一秒输出，并格式化当前的时间"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "884b4810",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-08T12:17:23.799359Z",
     "start_time": "2021-11-08T12:17:22.771082Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2021-11-08 20:17:23'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "time.sleep(1)\n",
    "time.strftime('%Y-%m-%d %H:%M:%S')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "941d7c20",
   "metadata": {},
   "source": [
    "### 9*9乘法表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "0f565cbb",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-31T13:58:27.079913Z",
     "start_time": "2021-10-31T13:58:27.064928Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "猫的名字叫tom，今年2岁了\n"
     ]
    }
   ],
   "source": [
    "# f-strings：f\"{}....\"\n",
    "name = \"tom\"\n",
    "age = 2\n",
    "\n",
    "print(f\"猫的名字叫{name}，今年{age}岁了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "105b46a8",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-08T12:58:06.019077Z",
     "start_time": "2021-11-08T12:58:06.010075Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1=1\t \n",
      "1*2=2\t 2*2=4\t \n",
      "1*3=3\t 2*3=6\t 3*3=9\t \n",
      "1*4=4\t 2*4=8\t 3*4=12\t 4*4=16\t \n",
      "1*5=5\t 2*5=10\t 3*5=15\t 4*5=20\t 5*5=25\t \n",
      "1*6=6\t 2*6=12\t 3*6=18\t 4*6=24\t 5*6=30\t 6*6=36\t \n",
      "1*7=7\t 2*7=14\t 3*7=21\t 4*7=28\t 5*7=35\t 6*7=42\t 7*7=49\t \n",
      "1*8=8\t 2*8=16\t 3*8=24\t 4*8=32\t 5*8=40\t 6*8=48\t 7*8=56\t 8*8=64\t \n",
      "1*9=9\t 2*9=18\t 3*9=27\t 4*9=36\t 5*9=45\t 6*9=54\t 7*9=63\t 8*9=72\t 9*9=81\t \n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10):\n",
    "    for a in range(1,i+1):\n",
    "        print(f\"{a}*{i}={i*a}\",end = '\\t ')         \n",
    "                 # end=\"\" 就是在同一行显示     end=\"\\t\" 空一格显示  end=\"\\t\\t...\" 空几格显示\n",
    "    print(\"\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6d31a88e",
   "metadata": {},
   "source": [
    "### 输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "3d68c2ca",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-08T12:57:16.088683Z",
     "start_time": "2021-11-08T12:57:08.149800Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一格字符：你好 welcome!!!\n",
      "中英文字母个数:9\n",
      "空格个数:1\n",
      "数字个数：0\n",
      "其它字符个数：3\n"
     ]
    }
   ],
   "source": [
    "import string\n",
    "a = input(\"请输入一格字符：\")\n",
    "alpha=0\n",
    "space=0\n",
    "digit=0\n",
    "others=0\n",
    "for i in a:\n",
    "    if i.isalpha():    # string中的is判断函数\n",
    "        alpha += 1\n",
    "    elif i.isspace():\n",
    "        space += 1\n",
    "    elif i.isdigit():\n",
    "        digit += 1\n",
    "    else:\n",
    "        others += 1\n",
    "print('中英文字母个数:%d'%alpha)\n",
    "print('空格个数:%d'%space)\n",
    "print('数字个数：%d'%digit)\n",
    "print('其它字符个数：%d'%others)\n",
    "            \n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "81001061",
   "metadata": {},
   "source": [
    "### 投票系统（选班长）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "269379f3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-08T13:33:31.792958Z",
     "start_time": "2021-11-08T13:33:31.770938Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# max（）函数\n",
    "# 1.查找数组中的最大整数/字符串\n",
    "# nums = {1,2,6,8,10,22}/{{\"45\",\"999\"}\n",
    "# max(nums)\n",
    "# 2.查找最大键或值\n",
    "# names={'AA':5,'BB':10,'CC':0}\n",
    "# max(names.values()) \n",
    "# max(names.keys()) \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "61eaf9c6",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-08T13:34:13.234731Z",
     "start_time": "2021-11-08T13:34:09.877803Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你支持的候选人(AA/BB/CC)CC\n",
      "{'AA': 0, 'BB': 0, 'CC': 1}\n",
      "恭喜CC成为班长\n"
     ]
    }
   ],
   "source": [
    "student={'AA':0,'BB':0,'CC':0}\n",
    "count=0\n",
    "while count<1:\n",
    "    name=input(\"请输入你支持的候选人(AA/BB/CC)\")\n",
    "    if name=='AA':\n",
    "       student['AA']+=1\n",
    "    elif name=='BB':\n",
    "       student['BB']+=1\n",
    "    else:\n",
    "       student['CC']+=1\n",
    "   \n",
    "    count+=1\n",
    "print(student)\n",
    "max(student.values())   # 通过max()函数找到字典中的value最大值\n",
    "for key,value in student.items():\n",
    "    if(value == max(student.values())):  # 通过value= 遍历字典找出所有value= 的键值对\n",
    "        print('恭喜%s成为班长'%key)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "98f33dfe",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
